/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bankingsystem;

import java.util.Calendar;

/**
 * Defines the SavingsAccount object that models a savings account.
 * @author Gokul
 * @version 1.0
 */
public class SavingsAccount extends Account{
    /*defining variables that are complementary to the variables defined in the parent Account class*/
    private float interestRate;

    /**
     * Template for a new SavingsAccount object.
     * @param accountNo the number of the account
     * @param customer the customer who is owning the account
     * @param balance  the account balance
     * @param startDate the date on which the account starts
     * @param interest the annual interest rate of the account
     */
    SavingsAccount(String accountNo,Customer customer,float balance,Calendar startDate, float interest){
       super(accountNo, customer, balance, startDate);
       this.interestRate = interest;
    }
    /**
     * Deposit a given amount to the account
     * @param f the value that needs to be deposited
     */
    public void deposit(float f){
        this.balance += f;
    }

    /**
     * withdraw a specified amount from the account. unlike in a current account, withdrawing
     * amounts larger than the account balance is not permitted.
     * @param f that account that should be withdrawn
     */
    public boolean withdraw(float f){
        if(this.balance>f){
            /*if the requested amount is within the limits, debit the account with that amount.*/
            this.balance -= f;
            return true;    /*transaction successful*/
        }
        else{
            /*or warn the user.*/
            System.out.println("Error processig request: insufficient funds.");
            return false;   /*transaction failed*/
        }
    }
    /**
     * This overridden method is used to display all details of the corresponding
     * SavingsAccount object when invoked.
     */
    @Override
    public void show() {
        System.out.println("\n--Savings account "+this.accountNo+" details:--"
                            +"\nHolder ID: "+this.customer.getCustomerID()
                            +"\nBalance: "+Float.toString(this.balance)
                            +"\nInterest rate: "+Float.toString(this.interestRate)
                            );
    }
    
    /**
     * Used to obtain the account number of the current SavingsAccount class.
     * @return the account number.
     */
    public String getAccountNo(){
        return this.accountNo;
    }
}
